grammar LL1AST;

options{
	language=Python;
	output=AST;
}

tokens {
	EXPRESION;
	CONC;
	DIV;
	SUB;
	SUP;
	PARENTESIS;
}

// Producciones
program : expresion EOF -> ^(EXPRESION expresion) ;	 
expresion : division;
division: (d1=conc -> $d1) ('/' d2=conc -> ^(DIV $division $d2) )* ;
conc : indexp (indexp+ ->  ^(CONC indexp+)| -> indexp) ;
indexp 	: val=valor (
					 ('^'v1=valor ('_' v2=valor)?)->^(SUP $val $v1? $v2? )
					|('_' v3=valor ('^' v4=valor)?)->^(SUB $val $v3? $v4? )
					| -> $val
					);
valor 	: ATOMO
	|	'('  expresion ')' -> ^(PARENTESIS expresion) 
	|	'{'!  expresion '}'! ;

// Terminales
NEWLINE: ('\r')? '\n' ;
ATOMO : ~(')'|'('|'{'|'}'|'^'|'_'|'/'|'\r'|'\n' );	  	 

